<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品海报模板</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: "Microsoft YaHei", Arial, sans-serif;
            background: transparent;
        }
        
        /* 海报容器 */
        .poster-container {
            width: 600px;
            height: 900px;
            position: relative;
            overflow: hidden;
            background-color: #ffffff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        
        /* 商品图片区域 */
        .product-image-container {
            width: 100%;
            height: 60%;
            overflow: hidden;
            position: relative;
        }
        
        .product-image {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        
        /* 商品信息区域 */
        .product-info {
            padding: 30px;
        }
        
        .product-title {
            font-size: 32px;
            font-weight: bold;
            color: #333;
            margin-bottom: 15px;
            line-height: 1.3;
        }
        
        .product-description {
            font-size: 18px;
            color: #666;
            line-height: 1.5;
            margin-bottom: 20px;
            max-height: 108px;
            overflow: hidden;
            display: -webkit-box;
            -webkit-line-clamp: 4;
            -webkit-box-orient: vertical;
        }
        
        /* 价格和购买区域 */
        .product-price-container {
            display: flex;
            align-items: center;
            margin-bottom: 25px;
        }
        
        .product-price {
            font-size: 36px;
            font-weight: bold;
            color: #ff4d4f;
        }
        
        .product-original-price {
            font-size: 20px;
            color: #999;
            text-decoration: line-through;
            margin-left: 15px;
        }
        
        /* 底部区域 */
        .poster-footer {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 30px 30px;
        }
        
        /* 店铺信息 */
        .shop-info {
            display: flex;
            align-items: center;
        }
        
        .shop-logo {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            margin-right: 10px;
        }
        
        .shop-name {
            font-size: 18px;
            font-weight: bold;
            color: #333;
        }
        
        /* 二维码 */
        .qrcode {
            width: 100px;
            height: 100px;
        }
        
        /* 折扣标签 */
        .discount-tag {
            position: absolute;
            top: 20px;
            right: 0;
            background-color: #ff4d4f;
            color: white;
            padding: 8px 15px;
            font-size: 20px;
            font-weight: bold;
            transform: translateX(5px);
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
            z-index: 10;
        }
        
        .discount-tag::before {
            content: "";
            position: absolute;
            left: -20px;
            top: 0;
            border-style: solid;
            border-width: 0 0 43px 20px;
            border-color: transparent transparent #ff4d4f transparent;
        }
    </style>
</head>
<body>
    <div class="poster-container" id="custom-poster">
        <!-- 商品图片区域 -->
        <div class="product-image-container">
            <img class="product-image" id="product-image" src="" alt="商品图片">
            <div class="discount-tag" id="discount-tag">8.5折</div>
        </div>
        
        <!-- 商品信息区域 -->
        <div class="product-info">
            <h1 class="product-title" id="product-title">优质商品名称</h1>
            <p class="product-description" id="product-description">这是一段商品描述，可以介绍商品的特点、材质、用途等信息。这里可以放置商品的简短介绍，帮助顾客了解商品的卖点。</p>
            
            <div class="product-price-container">
                <div class="product-price" id="product-price">¥299</div>
                <div class="product-original-price" id="product-original-price">¥399</div>
            </div>
        </div>
        
        <!-- 底部区域 -->
        <div class="poster-footer">
            <div class="shop-info">
                <img class="shop-logo" id="shop-logo" src="" alt="店铺logo">
                <div class="shop-name" id="shop-name">品牌店铺</div>
            </div>
            
            <img class="qrcode" id="qrcode" src="" alt="二维码">
        </div>
    </div>

    <script>
        // 根据传入的数据生成模板
        function generateTemplate(data) {
            // 默认值
            const defaults = {
                title: '优质商品名称',
                description: '这是一段商品描述，可以介绍商品的特点、材质、用途等信息。这里可以放置商品的简短介绍，帮助顾客了解商品的卖点。',
                price: '¥299',
                originalPrice: '¥399',
                discount: '8.5折',
                productImage: '',
                shopName: '品牌店铺',
                shopLogo: '',
                qrcode: '',
                showDiscount: true
            };
            
            // 合并数据
            const templateData = {...defaults, ...data};
            
            // 构建HTML
            let html = `
                <!-- 商品图片区域 -->
                <div class="product-image-container">
                    <img class="product-image" id="product-image" src="${templateData.productImage || ''}" alt="商品图片">
                    ${templateData.showDiscount ? `<div class="discount-tag" id="discount-tag">${templateData.discount}</div>` : ''}
                </div>
                
                <!-- 商品信息区域 -->
                <div class="product-info">
                    <h1 class="product-title" id="product-title">${templateData.title}</h1>
                    <p class="product-description" id="product-description">${templateData.description}</p>
                    
                    <div class="product-price-container">
                        <div class="product-price" id="product-price">${templateData.price}</div>
                        <div class="product-original-price" id="product-original-price">${templateData.originalPrice}</div>
                    </div>
                </div>
                
                <!-- 底部区域 -->
                <div class="poster-footer">
                    <div class="shop-info">
                        <img class="shop-logo" id="shop-logo" src="${templateData.shopLogo || ''}" alt="店铺logo">
                        <div class="shop-name" id="shop-name">${templateData.shopName}</div>
                    </div>
                    
                    <img class="qrcode" id="qrcode" src="${templateData.qrcode || ''}" alt="二维码">
                </div>
            `;
            
            return html;
        }
        
        // 如果是浏览器环境
        if (typeof window !== 'undefined' && typeof document !== 'undefined') {
            document.addEventListener('DOMContentLoaded', function() {
                // 可以在这里添加初始化代码
                console.log('商品海报模板初始化完成');
            });
        }
    </script>
</body>
</html> 